package com.orphan.util.mqConfig;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class OrderHandleMq {
    @Autowired
    CachingConnectionFactory cachingConnectionFactory;

    /**
     * 订单信息交换机
     * @return
     */
    @Bean
    public DirectExchange orderExchange(){
        return new DirectExchange("orderExchange");
    }


    /**
     * 订单信息队列
     * @return
     */
    @Bean
    public Queue orderQueue(){
        return new Queue("orderQueue");
    }



    /**
     * 订单信息信息交换机与队列绑定
     * @return
     */
    @Bean
    public Binding orderBinding(){
        return BindingBuilder.bind(orderQueue()).to(orderExchange()).with("orderKey");
    }

    /**
     * 订单信息交换机
     * @return
     */
    @Bean
    public DirectExchange newOrderExchange(){
        return new DirectExchange("newOrderExchange");
    }


    /**
     * 订单信息队列
     * @return
     */
    @Bean
    public Queue newOrderQueue(){
        return new Queue("newOrderQueue");
    }



    /**
     * 订单信息信息交换机与队列绑定
     * @return
     */
    @Bean
    public Binding newOrderBinding(){
        return BindingBuilder.bind(newOrderQueue()).to(newOrderExchange()).with("newOrderKey");
    }
}
